package com.sweet.fourtimeoa.controller;

import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.dto.SystemUserList;
import com.sweet.fourtimeoa.pojo.dto.SystemUserQueryDto;
import com.sweet.fourtimeoa.pojo.entity.Roles;
import com.sweet.fourtimeoa.pojo.entity.Users;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.service.UserService;
import com.sweet.fourtimeoa.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Tag(name = "用户管理")
@RestController
@RequestMapping("/oa/users")
@CrossOrigin(origins = "*")
public class UserController {
    @Autowired
    private UserService userService;
    //获取所有用户信息
    @Operation(summary = "获取所有用户信息")
    @PostMapping("/getAllUser")
    public Result getAllUser(@RequestBody PageDto<SystemUserQueryDto> pageDto) {
       PageVo<Users> users = userService.getAllUser(pageDto);
        return Result.success(users);
    }
    //分页查询
    @Operation(summary = "分页查询")
    @PostMapping("/querySystemUserList")
    public Result querySystemUserList(@RequestBody PageDto<SystemUserQueryDto> pageDto) {
        PageVo<SystemUserList> users = userService.querySystemUserList(pageDto);
        return Result.success(users);
    }
    @Operation(summary = "新增")
    @PostMapping("/insertUser")
    public Result insertUser(@RequestBody Users user) {
        userService.insertUser(user);
        return Result.success();
    }
    @Operation(summary = "用户管理_新增_查询角色表")
    @PostMapping("/queryRolesList")
    public Result queryRolesList() {
        return Result.success(userService.queryRolesList());
    }
    @Operation(summary = "用户管理_新增_查询部门表")
    @PostMapping("/queryDepartmentsList")
    public Result queryDepartmentsList() {
        return Result.success(userService.queryDepartmentsList());
    }
    @Operation(summary = "用户管理_删除")
    @DeleteMapping("/deleteUser/{userId}")
    public Result deleteUser(@PathVariable Integer userId) {
        return Result.success(userService.deleteUser(userId));
    }
    @Operation(summary = "用户管理_修改_获取数据")
    @GetMapping("/queryUserById/{userId}")
    public Result queryUserById(@PathVariable Integer userId) {
        return Result.success(userService.queryUserById(userId));
    }
    @Operation(summary = "用户管理_修改")
    @PutMapping("/updateUser")
    public Result updateUser(@RequestBody Users users) {
        userService.updateUser(users);
        return Result.success();
    }
    @Operation(summary = "修改密码_根据id获取密码")
    @GetMapping("/getUserByUserId/{userId}")
    public Result getUserByUserId(@PathVariable Integer userId) {
        return Result.success(userService.getUserByUserId(userId));
    }
    @Operation(summary = "修改密码")
    @PutMapping("/updatePassword")
    public Result updatePassword(@RequestParam String password, @RequestParam Integer userId) {
        userService.updatePassword(password,userId);
        return Result.success();
    }
}
